package controller

import (
	"gin/response"
	"gin/service"
	"gin/types"
	"github.com/gin-gonic/gin"
)

type ProductionManage struct {
}

var reviewRequestService service.ProductionManage
var DirectorStar service.DirectorStar

// List 制片管理-列表
func (P *ProductionManage) List(ctx *gin.Context) {

	var req types.ProductionManageReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	tenantId := service.GetInt64FromContext(ctx, "tenant_id")
	resData, queryErr := reviewRequestService.List(req, tenantId, req.Page, ctx)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// Info 制片管理-详情
func (P *ProductionManage) Info(ctx *gin.Context) {

	var req types.ProductionManageInfoReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	tenantId := service.GetInt64FromContext(ctx, "tenant_id")
	resData, queryErr := reviewRequestService.Info(req, tenantId, req.Page)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// TodayCount 今日统计
func (P *ProductionManage) TodayCount(ctx *gin.Context) {

	var req types.TodayCountReq

	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	//userId := service.GetInt64FromContext(ctx, "user_id")
	resData, queryErr := reviewRequestService.TodayCount(ctx, req)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProgressCount 今日统计
func (P *ProductionManage) ProgressCount(ctx *gin.Context) {

	var req types.ProgressCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	//userId := service.GetInt64FromContext(ctx, "user_id")
	resData, queryErr := reviewRequestService.ProgressCount(ctx, req)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

//GetMonthPlanTodoTaskProgress 获取当前月计划代办任务进度
func (P *ProductionManage) GetPlanTodoTaskProgress(ctx *gin.Context) {
	var req types.GetMonthPlanTodoTaskProgressReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	resData, queryErr := reviewRequestService.GetPlanTodoTaskProgress(ctx, req.ProjectId, req.EpisodeId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

//GetMonthPlanTodoTaskProgress 获取当前月计划代办任务进度
func (P *ProductionManage) EpisodeTaskCount(ctx *gin.Context) {
	var req types.EpisodeTaskCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	resData, queryErr := reviewRequestService.EpisodeTaskCount(req.ProjectId, req.StepCategoryIds, req.EpisodeId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}

}

//reviewFeedbackCount 审核统计
func (P *ProductionManage) ReviewFeedbackCount(ctx *gin.Context) {
	var req types.ReviewFeedbackCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	resData, queryErr := reviewRequestService.ReviewFeedbackCount(ctx, req.ReviewFeedbackId, req.ProjectId, req.EpisodeCode)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}

}

// DirectorStar 导演关注
func (P *ProductionManage) DirectorStar(ctx *gin.Context) {

	var req types.DirectorStarReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	resData, queryErr := DirectorStar.List(ctx, req, req.Page)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

//TotalTaskCount 总进度详情任务统计
func (P *ProductionManage) TotalTaskCount(ctx *gin.Context) {
	var req types.TotalTaskCountReq
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	resData, queryErr := reviewRequestService.TotalTaskCount(req.Param.Filter)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}
